<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
<link rel="stylesheet" href="./static/css/bootstrap.min.css">
<style>
    body {
        padding-top: 50px;
    }
    .form-container {
        max-width: 300px;
        margin: 0 auto;
        padding: 20px;
        border: 1px solid #ccc;
        border-radius: 5px;
        background-color: #f9f9f9;
    }
    .form-group {
        margin-bottom: 15px;
    }
    .form-control {
        width: 100%;
        padding: 8px;
        box-sizing: border-box;
    }
    .btn-login {
        width: 100%;
        padding: 10px;
        background-color: #5cb85c;
        color: white;
        border: none;
        border-radius: 5px;
        cursor: pointer;
    }
    .btn-login:hover {
        background-color: #4cae4c;
    }
    .register-link {
        display: block;
        text-align: center;
        margin-top: 15px;
    }
</style>
</head>
<body>
<div class="form-container">
    <h2 class="text-center">登录</h2>
    <form>
        <div class="form-group">
            <label for="ipt-username">用户名:</label>
            <input type="text" class="form-control" id="ipt-username" name="username" required>
        </div>
        <div class="form-group">
            <label for="ipt-pwd">密码:</label>
            <input type="password" class="form-control" id="ipt-pwd" name="password" required>
        </div>
        <button type="button" id="btn-login" class="btn-login">登录</button>
        <a href="register.html" class="register-link">立即注册</a>
    </form>
</div>
<script src="./static/js/axios.min.js"></script>
<script>
    // 获取元素 对象绑定事件
    let btnLogin = document.getElementById("btn-login");
    btnLogin.onclick = function () {
        // 点击获取输入框的值
        let username = document.getElementById("ipt-username").value;
        let password = document.getElementById("ipt-pwd").value;

        // 发请求
        let url = "/user/login";
        let data = {
            'number': username,
            'password': password
        };
        axios.post(url, data).then(function (response) {
            console.log(response.data);
            if (response.data.code === 200) {
                alert("登录成功");
                window.location.href = "index.html?username=" + username;
            } else if (response.data.code === 400) {
                alert(response.data.msg);
            }
        });
    };
</script>
</body>
</html>